cmake_minimum_required(VERSION 3.16)
project(Ui VERSION 0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 REQUIRED COMPONENTS Core)
find_package(OpenCV REQUIRED)
find_package(Qt6 REQUIRED COMPONENTS Quick Core Network Sql)

# 添加 Boost 依赖
find_package(Boost REQUIRED COMPONENTS system)

# 使用 Boost.Asio 的头文件模式
add_definitions(-DBOOST_ASIO_HEADER_ONLY)

qt_standard_project_setup(REQUIRES 6.8)

# 添加 websocket 服务器
qt_add_library(websocketserver SHARED
    websocketserver.h
    websocketserver.cpp
)

target_link_libraries(websocketserver
    PRIVATE
        Qt6::Core
        Qt6::Network
        Boost::system
)

# 修改 networkmanager
qt_add_library(networkmanager SHARED
    networkmanager.h
    networkmanager.cpp
)

target_link_libraries(networkmanager
    PRIVATE
        Qt6::Network
        Qt6::Core
        Qt6::Gui
        Boost::system
        websocketserver
)

# 主应用程序
qt_add_executable(appUi
    main.cpp
    videocontroller.h
    videocontroller.cpp
    videoimageprovider.h
    videoimageprovider.cpp
    userdatabase.h
    userdatabase.cpp
)

qt_add_qml_module(appUi
    URI Ui
    VERSION 1.0
    QML_FILES
        Main.qml
        ConnectScreen.qml
        ChatScreen.qml
        LoginScreen.qml
        StartScreen.qml
        SOURCES userdatabase.h userdatabase.cpp
        QML_FILES RegisterScreen.qml
)

target_include_directories(appUi PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${OpenCV_INCLUDE_DIRS}
)

target_link_libraries(appUi
    PRIVATE
        Qt6::Quick
        Qt6::Core
        Qt6::Network
        Qt6::Gui
        Qt6::Sql
        networkmanager
        websocketserver
        ${OpenCV_LIBS}
        Boost::system
)
target_link_libraries(appUi PRIVATE Qt6::Core)

include(GNUInstallDirs)
install(TARGETS appUi
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(TARGETS networkmanager websocketserver
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
